package com.peaker.advertisingpro.activity

import android.content.Context
import android.content.pm.ActivityInfo
import android.media.AudioManager
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.peaker.advertisingpro.R
import com.peaker.advertisingpro.listener.OnDownloadListener
import com.peaker.advertisingpro.utils.Common
import com.peaker.advertisingpro.utils.HttpUtil
import com.peaker.advertisingpro.utils.SPUtil
import com.peaker.advertisingpro.utils.SmdtManagerUtils
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_test.*
import kotlinx.android.synthetic.main.activity_test.rootView
import java.io.File


class TestActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)


//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)//横屏设置
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)//竖屏设置
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)//默认设置


//        dowmProgramFun()
        btn.setOnClickListener {
//            var progress = seekbar.progress
//
//            Log.d("TestActivity","当前值是: $progress")
//
//            var smdtSetAndroidVolume = SmdtManagerUtils.smdtSetAndroidVolume(progress)
//            SPUtil.putSP(Common.VOLUME,smdtSetAndroidVolume.toString())
//            var currentSysVolume = SmdtManagerUtils.getCurrentSysVolume()
//            var streamMaxVolume= SmdtManagerUtils.getMaxSysVolume()
//
//            Log.d("TestActivity","最大值: $streamMaxVolume")
//            Log.d("TestActivity","设置后的值是: $smdtSetAndroidVolume")
//            Log.d("TestActivity","设置后的值是2: $currentSysVolume")
            Settings.System.putInt(this.contentResolver, Settings.System.ACCELEROMETER_ROTATION,90)

            

//            (ScrollActivity.scrollAsc as ScrollActivity).setScreenonChange("90")



            if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
            {

                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
            }
//横屏反方向
            else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
            {

                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
            }

//纵屏正方向

            else if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
            {

                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT)
            }
//纵屏反方向
            else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT)
            {

                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
            }
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
        }

    }

    private fun dowmProgramFun() {
        println("测试 开始 ")

        var downUrl = "http://123.57.26.191:8899/publish/getPublishZip?id=d4d443b1f5094693a45530d72bf11338"
        HttpUtil.downloadFile(
            downUrl,
            Common.DIRADDRESS,
            "d4d443b1f5094693a45530d72bf11338.zip",
            object : OnDownloadListener {
                override fun onDownloadSuccess(file: File?) {
                    println("测试  下载成功")

                }

                override fun onDownloading(progress: Int) {
                    println("测试  下载中$progress")
                }

                override fun onDownloadFailed(e: Exception?) {
                    println("测试  下载失败${e?.message}")
                }

            })
    }



}
